<script type="text/ecmascript-6">
   import Navbar from '../../components/base/navbar.vue';
   export default{
      name:"coach_my_activity",
      components:{
          Navbar
      },
      data(){
          return {
              tabList:[
                {
                  id:0,
                  name:"全部",
                  page: 0,
                  hasMore: true,
                  init: false,
                  isList:false
                },
                {
                  id:1,
                  name:"进行中",
                  page: 0,
                  hasMore: true,
                  init: false,
                  isList:false
                },
                {
                  id:2,
                  name:"已结束",
                  page: 0,
                  hasMore: true,
                  init: false,
                  isList:false
                }
              ],
              dataList:{

              },
              tabIndex:0,
              isList:false,
              heights:"100%",
              isDrag:false
          }
      },
     methods:{
       loadMore(){
         var page = this.tabList[this.tabIndex].page + 1;
         this.$store.dispatch("queryMyLeadActivity",{index:this.tabIndex,page:page});
       },
       refresh(){
         this.$store.dispatch("queryMyLeadActivity",{index:this.tabIndex});
       },
       done(){
         this.$nextTick(() => {
           this.$refs.pulldown[this.tabIndex].onLoadOff();
         })
       },
       coachActivityList (res, index){
           let list,
           page=res.meta.pagination,
           current_page =page.current_page,
           total_pages =page.total_pages;

           if( current_page ==1){
               list =res.data;
           }else{
               list =this.dataList[index].concat(res.data);
           }
//           this.tabIndex=index;
           this.$set(this.dataList,index,list);
           this.tabList[index].init = true;
           this.tabList[index].page = current_page;
           this.tabList[index].hasMore = current_page < total_pages;
           if(list.length ==0){
             this.isList =true;
           }else{
             this.isList=false;
           }
           this.$emit("done");
//           this.$refs.pulldown[this.tabIndex].onLoadOff();
       },
       jump(page, id) {
         this.$router.push({ name: page, params: {id: id} });
       },
       change(i){
           console.log(1);
         this.tabIndex=i;
         this.$router.replace({name: 'mylead_activity', params: {index: this.tabIndex}});
         if(!this.tabList[i].init){
           this.$store.dispatch('queryMyLeadActivity',{index:this.tabIndex})
         }
         else{
           this.isList=!!!this.dataList[i].length;
         }
       }
     },
     created(){
        EventBus.$on("coach-activityList",this.coachActivityList);
        this.$on("done",this.done);
       this.tabIndex = Number(this.$route.params.index) || 0;
       this.$store.dispatch("queryMyLeadActivity",{
           index:this.tabIndex
       })
     },
     beforeDestory(){
         EventBus.$off("coach-activityList");
     }
   }
</script>
